package com.szholly.plug.safe.entity.fun;

import java.util.HashMap;
import java.util.LinkedHashMap;

import org.springframework.stereotype.Component;

import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.data.general.*;
import com.szholly.data.general.metadata.IBaseTable;

/**
 * 定义系统功能表
 */
@Component("SAFE_FUNCTION")
public class FunctionService extends InterceptorTableBase implements IBaseTable {

	public final static String TABLE_NAME = "SAFE_FUNCTION";

	/**
	 * 获取单例对象
	 */
	public static FunctionService getSingleRef() {
		return (FunctionService) SpringBeanFactory.getBean("SAFE_FUNCTION");
	}

	@Override
	public String getMetadataTableName() {
		return TABLE_NAME;
	}

	@Override
	public String getMetadataTableAliasName() {
		return "功能权限表";
	}

	private HashMap<String, Field> fields;

	@Override
	protected HashMap<String, Field> fields() {
		if (fields == null) {
			fields = new HashMap<String, Field>();

			Field itemField = new Field();
			
			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_FUNCTIONID);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(2);
			itemField.setFieldAliasName("功能主键");
			itemField.setCanShow(true);
			itemField.setIsKey(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_C_FUNCTIONBH);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(3);
			itemField.setFieldAliasName("功能编号");
			itemField.setCanShow(true);
			itemField.setUniqueGroup("功能编号");
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_C_FUNCTIONNAME);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(4);
			itemField.setFieldAliasName("功能名称");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_C_FUNCTIONDES);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(5);
			itemField.setFieldAliasName("功能描述");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_PID);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("父节点ID");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_C_FUNCTIONURL);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(9);
			itemField.setFieldAliasName("功能地址");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_C_FUNCTIONTYPE);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(10);
			itemField.setFieldAliasName("功能类型");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			
			HashMap<String, String>	codes = new LinkedHashMap<String,String>();
			codes.put("1", "android");
			codes.put("2", "web");
			IDomain pDomain = new MemDomain(codes, "(运维)功能权限类型");
			itemField.setDomain(pDomain);
			
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_I_ORDER);
			itemField.setDataType(GlobalDataType.Int32);
			itemField.setFieldID(9);
			itemField.setFieldAliasName("排序字段");
			itemField.setCanShow(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_JB);
			itemField.setDataType(GlobalDataType.Int32);
			itemField.setFieldID(9);
			itemField.setFieldAliasName("机构级别");
			itemField.setCanShow(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(FunctionEntity.FIELD_ISCHILD);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("是否为叶子节点");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
		}
		return fields;
	}

	/**
	 * 表分组信息
	 */
	@Override
	public String getTableGroup() {
		return "用户权限控制";
	}

	@Override
	public String getCodeFieldName() {
		return FunctionEntity.FIELD_C_FUNCTIONBH;
	}

	@Override
	public String getCaptionFieldName() {
		return FunctionEntity.FIELD_C_FUNCTIONNAME;
	}

	@Override
	public boolean getIsCodeTable() {
		return true;
	}

	@Override
	public boolean getIsManageCodeTable() {
		return false;
	}

	@Override
	public String getGUIDFieldName() {
		return FunctionEntity.FIELD_FUNCTIONID;
	}
	
	/**
	 * 获取级别字段名
	 */
	@Override
	public String getLevelFieldName(){
		return FunctionEntity.FIELD_JB;
	}
	
	/**
	 * 获取是否为叶子节点字段名
	 */
	@Override
	public String getIsChildFieldName() {
		return FunctionEntity.FIELD_ISCHILD;
	}

	@Override
	public String getIDFieldName() {
		return FunctionEntity.FIELD_FUNCTIONID;
	}

	@Override
	public String getPIDFieldName() {
		return FunctionEntity.FIELD_PID;
	}
	
	@Override
	public boolean getIsTreeTable() {
		return true;
	}
}